<template>
	<MkPanel title="输血前评估" class="edit-assessment-form">
		<el-row :gutter="20" style="padding-bottom: 10px;">
			<el-col :span="12">
				<MkForm>
					<MkInput v-model="model.shuXueZhiZheng" label="输血指征" :isEdit="isEdit" />
					<MkInput v-model="model.bingQingFenXi" label="病情分析" :isEdit="isEdit" type="textarea"
						:autosize="{ minRows: 2, maxRows: 4 }" />
					<MkInput v-model="model.chuXueLiang" label="出血量" :isEdit="isEdit" />
				</MkForm>
			</el-col>
			<el-col :span="12">
				<el-checkbox-group v-model="list" @change="jiSuan">
					<el-checkbox v-for="(item, index) in basShuXueZhiZheng" :key="index" :label="item.mingCheng"
						:value="item" :disabled="!isEdit" />
				</el-checkbox-group>
			</el-col>
		</el-row>
	</MkPanel>
</template>
<script lang="ts" setup>
// 输血前评估
import { TraShenQingHuanZheInput } from '/@/api/tra/TraShenQing';
import { clog, clone, isNull } from '/@/utils';

const props = defineProps({
	isEdit: {
		type: Boolean,
		default: true,
	},
	pingGuInput: { // 合理性评估的入参
		type: Object,
		default: {} as PingGuInput,
	}
})
const model = defineModel({ required: true, default: {} as TraShenQingHuanZheInput })

const list = ref([])
const listSelected = ref([])

// 输血指征
const basShuXueZhiZheng = [
	{ pId: -1, mingCheng: '输血指征选项1', functionBody: 'return (p.Hb>50 && p.nianLing>70)' },
	{ pId: -1, mingCheng: '输血指征选项2', functionBody: 'return (p.Hb>=50 && p.nianLing>70)' },
	{ pId: -1, mingCheng: '输血指征选项3', functionBody: '' },
	{ pId: -1, mingCheng: '输血指征选项4', functionBody: 'return (p.Hb>50 && p.nianLing>70)' },
	{ pId: -1, mingCheng: '输血指征选项5', functionBody: 'return (p.Hb>50 && p.nianLing>70)' },
	{ pId: -1, mingCheng: '输血指征选项6', functionBody: 'return (p.Hb>50 && p.nianLing>70)' },
	{ pId: -1, mingCheng: '输血指征选项7', functionBody: 'return (p.Hb>50 && p.nianLing>70)' },
	{ pId: -1, mingCheng: '输血指征选项8', functionBody: 'return (p.Hb>50 && p.nianLing>70)' },
	{ pId: -1, mingCheng: '输血指征选项9', functionBody: 'return (p.Hb>50 && p.nianLing>70)' },
]

const jiSuan = () => {
	clog('合理性评估入参', props.pingGuInput);
	listSelected.value = clone(list.value);
	model.value.shuXueZhiZheng = ""
	listSelected.value.forEach((item: any) => {
		if (isNull(item.functionBody)) {
			item.pingGuJieGuo = ""
			model.value.shuXueZhiZheng += `${item.mingCheng} ; `;
		} else {
			let result = new Function('p', item.functionBody)(props.pingGuInput); // 动态执行函数
			item.pingGuJieGuo = result ? '合理' : '不合理'
			model.value.shuXueZhiZheng += `${item.mingCheng}(${item.pingGuJieGuo}) ; `;
		}
	})
	clog("合理性评估结果", listSelected.value);
}

</script>
<style lang="scss" scoped></style>
